using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using ApiTest.Api.Entity;
using System.Linq;
using ApiTest.Api.Db;
using ApiTest.Api.Repository;
using ApiTest.Api.Params;
using Microsoft.Extensions.Configuration;
using ApiTest.Api.Utils;
using Microsoft.AspNetCore.Authorization;
using Admin3000.Backend.Api.Params;

namespace ApiTest.Api.Controllers
{
    // [Authorize]
    [ApiController]
    [Route("[controller]")]
    public class SpuImageController : ControllerBase
    {
        private IConfiguration _configuration;
        private IRepository<SpuImage> _spuimageRepository;
        private TokenParameter _tokenParameter;

        public  SpuImageController(IConfiguration configuration, IRepository<SpuImage> spuimageRepository)
        {
            _configuration = configuration;
          _spuimageRepository = spuimageRepository;
            _tokenParameter = _configuration.GetSection("TokenParameter").Get<TokenParameter>();
        }

        [HttpGet]
        public dynamic Get()
        {
            var spuimage=_spuimageRepository.Table.ToList();

            return new{
                Code=1000,
                Data=spuimage,
                Msg="查询图表成功"
            };
        }
        [HttpPost]
        public dynamic Post(CreateSpuImage newSpuimage)
        {
            var spuimage=new SpuImage{
                SpuId=newSpuimage.SpuId,
                ImageId=newSpuimage.ImageId,
            };
            _spuimageRepository.Insert(spuimage);

            return new {
                Code=1000,
                Data=spuimage,
                Msg="添加商品图片成功"
            };
        }
        



        
        
        

        
       
    }
}